package mi.payment.admin.pay88;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import mi.payment.R;

public class PayAdapter extends RecyclerView.Adapter<PayAdapter.ViewHolder> {

    private Context context;
    private List<IPay88Wallet> list;

    PayAdapter(Context context, List<IPay88Wallet> list) {
        this.context = context;
        this.list = list;
    }

    private OnItemClickListener onItemClickListener;

    void setOnItemClickListener(OnItemClickListener l) {
        this.onItemClickListener = l;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
        View view = View.inflate(context, R.layout.admin_pay88_item_pay, null);
        view.setOnClickListener(
                v -> {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemClick(viewGroup, v, position);
                    }
                }
        );
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        IPay88Wallet item = list.get(position);
        holder.name.setText(item.name);
        holder.icon.setImageResource(item.iconResId);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView name;
        ImageView icon;

        ViewHolder(View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.iv_pay_icon);
            name = itemView.findViewById(R.id.tv_pay_name);
        }

    }

}